#ifndef CALIBRATION_H
#define CALIBRATION_H

#include <QThread>
#include <opencv2/opencv.hpp>
#include <vector>

class Calibration : public QThread
{
	Q_OBJECT

public:
	Calibration(QObject* parent = nullptr);
	~Calibration();

	void initBoard(const QString& fileName);
	void setImageList(QList<cv::Mat>* list);
	void correct(cv::Mat& inMat, cv::Mat& outMat);
	void save(const QString& fileName);
	void load(const QString& fileName);

	void syncRun();
	
	cv::Mat cameraMatrix;
	cv::Mat distCoeffs;

protected:
	virtual void run() override;

signals:
	void processed(bool, QString);

private:
	void findCorners(std::vector<std::vector<cv::Point2f>>& imagePoints);
	bool runCalibration(cv::Size& imageSize, std::vector<std::vector<cv::Point2f>>& imagePoints);
	
	cv::Size boardSize;
	double squareSize;
	QList<cv::Mat>* captureImages;
	const std::string winTitle = "Image View";
	const std::string srcImageTitle = "Source Image";
};

#endif
